close all; clc; clear;

original = imread("zyx.jpg");   % original是已经加载的图像变量
Gray_img1 = rgb2gray(original);      % 原始灰度图像
subplot(121);imshow(Gray_img1); title('原始图像');

Gray_img2 = im2double(Gray_img1);
[height, width] = size(Gray_img2);   % 获取图像尺寸

% Gray_img2(100, 100) %打印像素值 测试 - 双精度类型

threshold1 = 50 / 255;
threshold2 = 200 / 255;

% 遍历图像，计算每个灰度级的像素数量
for i = 1:height
    for j = 1:width
        if (Gray_img2(i,j) < threshold1)
            Gray_img2(i,j) = 0;    % 小于50 = 0
        elseif Gray_img2(i,j) <= threshold2
            Gray_img2(i,j) = Gray_img2(i,j); % 保持不变
        else
            Gray_img2(i,j) = 1;
        end
    end
end

subplot(122);imshow(Gray_img2); title('变换后图像');
